<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="店铺ID" prop="store_id">
                <el-input-number v-model="form.store_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="变更积分" prop="score">
                <el-input-number v-model="form.score"></el-input-number>
        	</el-form-item>
            <el-form-item label="变更前积分" prop="before">
                <el-input-number v-model="form.before"></el-input-number>
        	</el-form-item>
            <el-form-item label="变更后积分" prop="after">
                <el-input-number v-model="form.after"></el-input-number>
        	</el-form-item>
            <el-form-item label="备注" prop="memo">
                <el-input v-model="form.memo" clearable></el-input>
        	</el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio v-model="form.status" v-for="(item,index) in status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="类型" prop="typestatus_id">
                <el-input-number v-model="form.typestatus_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="公共id" prop="public_id">
                <el-input-number v-model="form.public_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="创建时间" prop="createtime">
                <el-date-picker v-model="form.createtime" type="datetime"></el-date-picker>
        	</el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					store_id: '',
					score: '',
					before: '',
					after: '',
					memo: '',
					status: '',
					typestatus_id: '',
					public_id: '',
					createtime: '',
                },
                rules: {
                },
				status_option:{"0":"未知","1":"支出","2":"收入"},
				typestatus_id_option:{"0":"未知","2":"邀请用户","3":"大转盘购买","4":"大转盘中奖","6":"每日签到"},
            }
        },
        methods: {
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.store_score_log[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>